/*
 * EditDoctor.java
 *
 * Created on September 1, 2008, 10:41 AM
 */

package Project.GUI;

import Project.bussiness.Check;
import Project.bussiness.Doctor;
import Project.bussiness.Factualy;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


public class EditDoctor extends javax.swing.JInternalFrame {
    
    /** Creates new form EditDoctor */
    private int flag=0;
    public EditDoctor() {
         try {
        
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
        initComponents();
        try{
        fac = Factualy.getAllFactualys();
        }catch(Exception e){
            e.printStackTrace();
        }
        for (int i=0;i<fac.size();i++){
            Factualy f = new Factualy();
            f=(Factualy) fac.get(i);
            cmbFactualy.addItem(f.getFactualyName());
        }            
//        Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
//        setBounds((screeSize.width-1000)/2,(screeSize.height-600)/2,1000,600);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblFiltered = new javax.swing.JLabel();
        cmbFillter = new javax.swing.JComboBox();
        lblLookFor = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listDoctor = new javax.swing.JList();
        txtLookFor = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();
        pnlHead = new javax.swing.JPanel();
        lblHead = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        pnlInformations = new javax.swing.JPanel();
        lblFirstName = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        lblLastName = new javax.swing.JLabel();
        txtLastName = new javax.swing.JTextField();
        lblAddress = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txaAddress = new javax.swing.JTextArea();
        lblFactualy = new javax.swing.JLabel();
        cmbFactualy = new javax.swing.JComboBox();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        lblPhone = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        lblSpeciality = new javax.swing.JLabel();
        txtSpeciality = new javax.swing.JTextField();
        lblAward = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txaAward = new javax.swing.JTextArea();
        lblAvailabitily = new javax.swing.JLabel();
        cmbAvailability = new javax.swing.JComboBox();
        pnlOptions = new javax.swing.JPanel();
        btnSaveChange = new javax.swing.JButton();
        btnEditDoctor = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        btnInsert = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setClosable(true);
        setResizable(true);
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 255)));
        lblFiltered.setText("Filtered By");

        cmbFillter.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "Name" }));

        lblLookFor.setText("Look For");

        listDoctor.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        listDoctor.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listDoctorValueChanged(evt);
            }
        });

        jScrollPane1.setViewportView(listDoctor);

        btnSearch.setText("OK");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(lblFiltered))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(lblLookFor))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbFillter, javax.swing.GroupLayout.Alignment.TRAILING, 0, 165, Short.MAX_VALUE)
                            .addComponent(txtLookFor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(70, Short.MAX_VALUE)
                .addComponent(btnSearch)
                .addGap(66, 66, 66))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFiltered)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbFillter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblLookFor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(txtLookFor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(btnSearch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pnlHead.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        lblHead.setFont(new java.awt.Font("Times New Roman", 2, 24));
        lblHead.setText("Information Of Doctor");

        javax.swing.GroupLayout pnlHeadLayout = new javax.swing.GroupLayout(pnlHead);
        pnlHead.setLayout(pnlHeadLayout);
        pnlHeadLayout.setHorizontalGroup(
            pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlHeadLayout.createSequentialGroup()
                .addContainerGap(258, Short.MAX_VALUE)
                .addComponent(lblHead, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(153, 153, 153))
        );
        pnlHeadLayout.setVerticalGroup(
            pnlHeadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlHeadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblHead, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 303, Short.MAX_VALUE)
        );

        pnlInformations.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Informations", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12)));
        lblFirstName.setText("First Name");

        txtFirstName.setEditable(false);

        lblLastName.setText("Last Name");

        txtLastName.setEditable(false);

        lblAddress.setText("Address");

        txaAddress.setColumns(20);
        txaAddress.setEditable(false);
        txaAddress.setRows(5);
        jScrollPane2.setViewportView(txaAddress);

        lblFactualy.setText("Factualy Name");

        cmbFactualy.setEditable(true);

        lblEmail.setText("Email");

        txtEmail.setEditable(false);

        lblPhone.setText("Phone");

        txtPhone.setEditable(false);

        lblSpeciality.setText("Speciality");

        txtSpeciality.setEditable(false);

        lblAward.setText("Award");

        txaAward.setColumns(20);
        txaAward.setEditable(false);
        txaAward.setRows(5);
        jScrollPane3.setViewportView(txaAward);

        lblAvailabitily.setText("Availability");

        cmbAvailability.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes", "No" }));
        cmbAvailability.setEnabled(false);

        javax.swing.GroupLayout pnlInformationsLayout = new javax.swing.GroupLayout(pnlInformations);
        pnlInformations.setLayout(pnlInformationsLayout);
        pnlInformationsLayout.setHorizontalGroup(
            pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformationsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFirstName)
                    .addComponent(lblLastName)
                    .addComponent(lblAddress)
                    .addComponent(lblFactualy)
                    .addComponent(lblAvailabitily))
                .addGap(18, 18, 18)
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInformationsLayout.createSequentialGroup()
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlInformationsLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtFirstName, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                            .addComponent(txtLastName)
                            .addComponent(jScrollPane2))
                        .addGap(27, 27, 27)
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblEmail)
                            .addComponent(lblPhone)
                            .addComponent(lblSpeciality)
                            .addComponent(lblAward)))
                    .addComponent(cmbAvailability, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbFactualy, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(txtPhone)
                    .addComponent(txtSpeciality)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
                .addContainerGap(47, Short.MAX_VALUE))
        );
        pnlInformationsLayout.setVerticalGroup(
            pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformationsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFirstName)
                    .addComponent(lblEmail)
                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLastName, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblPhone)
                        .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlInformationsLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblSpeciality)
                            .addComponent(txtSpeciality, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlInformationsLayout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(lblAward))
                            .addGroup(pnlInformationsLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(cmbAvailability, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblAvailabitily))))))
                    .addGroup(pnlInformationsLayout.createSequentialGroup()
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlInformationsLayout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(lblAddress))
                            .addGroup(pnlInformationsLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlInformationsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblFactualy)
                            .addComponent(cmbFactualy, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(23, 23, 23))
        );

        pnlOptions.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Options", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12)));
        btnSaveChange.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.gif")));
        btnSaveChange.setText("update");
        btnSaveChange.setEnabled(false);
        btnSaveChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveChangeActionPerformed(evt);
            }
        });

        btnEditDoctor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit.png")));
        btnEditDoctor.setText("Edit ");
        btnEditDoctor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditDoctorActionPerformed(evt);
            }
        });

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/delete.png")));
        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/exit.GIF")));
        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        btnInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.gif")));
        btnInsert.setText("Insert");
        btnInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInsertActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlOptionsLayout = new javax.swing.GroupLayout(pnlOptions);
        pnlOptions.setLayout(pnlOptionsLayout);
        pnlOptionsLayout.setHorizontalGroup(
            pnlOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlOptionsLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(btnSaveChange, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(btnEditDoctor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(btnInsert, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );
        pnlOptionsLayout.setVerticalGroup(
            pnlOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlOptionsLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(pnlOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClose)
                    .addComponent(btnDelete)
                    .addComponent(btnSaveChange)
                    .addComponent(btnEditDoctor)
                    .addComponent(btnInsert))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(pnlHead, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(pnlInformations, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(pnlOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(pnlHead, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(22, 22, 22)
                                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(pnlInformations, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 80, Short.MAX_VALUE)))
                        .addContainerGap(11, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(pnlOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        getContentPane().add(jPanel1, new java.awt.GridBagConstraints());

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed
// TODO add your handling code here:
        flag=0;
        reset();
        btnSaveChange.setEnabled(true);
        txtEmail.setEditable(true);
        txtFirstName.setEditable(true);
        txtLastName.setEditable(true);
        txtPhone.setEditable(true);
        txtSpeciality.setEditable(true);
        txaAddress.setEditable(true);
        txaAward.setEditable(true);
        cmbAvailability.setEnabled(true);
        cmbFactualy.setEnabled(true);
    }//GEN-LAST:event_btnInsertActionPerformed

    private void reset()
{
    txtEmail.setText("");
    txtFirstName.setText("");
    txtLastName.setText("");
    txtPhone.setText("");
    txtSpeciality.setText("");
    txaAddress.setText("");
    txaAward.setText("");
    cmbFactualy.setSelectedIndex(0);
    cmbAvailability.setSelectedIndex(0);
    
}
    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
    // TODO add your handling code here:
        if (index==-1){
            JOptionPane.showMessageDialog(this,"Select doctor to delete");
            return;
        }
        try{
            //index = listDoctor.getSelectedIndex();
            Doctor.deleteDoctor(index);
            JOptionPane.showMessageDialog(this,"Delete sucsses");
        }catch(SQLException sqle){
            JOptionPane.showMessageDialog(this,"Can't delete this doctor");
            sqle.printStackTrace();
        }
        create_list();
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnSaveChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveChangeActionPerformed
        // TODO add your handling code here:

        Doctor d = new Doctor();
        boolean chk = Check.checkName(txtFirstName.getText());
        if(!chk)
        {
            JOptionPane.showMessageDialog(this,"First Name is wrong");
            return;
        }
        else{
            d.setFirstName(txtFirstName.getText());
        }
        if (!Check.checkName(txtLastName.getText())){
            JOptionPane.showMessageDialog(this,"Last Name is wrong");
            return;
        }                
        else{
            d.setLastName(txtLastName.getText());        
        }
        if (!Check.checkEmail(txtEmail.getText())){
            JOptionPane.showMessageDialog(this,"Email is wrong");
            return;
        }else{
            d.setEmail(txtEmail.getText());
        }
        if (!Check.checkPhone(txtPhone.getText())){
            JOptionPane.showMessageDialog(this,"Phone is wrong");
            return;
        }else{
            d.setPhone(txtPhone.getText());
        }
        if (txaAddress.getText().length() == 0){
            JOptionPane.showMessageDialog(this,"Address can't blank");
            return;
        }else{
            d.setAddress(txaAddress.getText());
        }
        if(txtSpeciality.getText().length() == 0){
            JOptionPane.showMessageDialog(this,"Speciality can't blank ");
            return;
        }else{
            d.setSpeciality(txtSpeciality.getText());
        }
        if(txaAward.getText().length() == 0){
            JOptionPane.showMessageDialog(this,"Award can't blank");
            return;
        }else{
            d.setAward(txaAward.getText());
        }
        d.setAvailability(cmbAvailability.getSelectedIndex());
        int j = cmbFactualy.getSelectedIndex();
        Factualy f = (Factualy)fac.get(j);
        d.setFactualyID(f.getFactualyID());   
         if(flag==1)
        {
        try{            
            Doctor.updateDoctor(index,d);
            JOptionPane.showMessageDialog(this,"Update Successful");
        }catch(SQLException e){            
            JOptionPane.showMessageDialog(this,"Can't update doctor");
        }
         }
         else
         {
         try{
            Doctor.insertDoctor(d);
            JOptionPane.showMessageDialog(this,"Insert successful");
            reset();
        }catch(SQLException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(this,"Can't insert doctor");
        }
         }
        create_list();
        btnSaveChange.setEnabled(false);
        txtEmail.setEditable(false);
        txtFirstName.setEditable(false);
        txtLastName.setEditable(false);
        txtPhone.setEditable(false);
        txtSpeciality.setEditable(false);
        txaAddress.setEditable(false);
        txaAward.setEditable(false);
        cmbAvailability.setEnabled(false);
        cmbFactualy.setEnabled(false);
                
    }//GEN-LAST:event_btnSaveChangeActionPerformed

    private void btnEditDoctorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditDoctorActionPerformed
    // TODO add your handling code here:
        btnSaveChange.setEnabled(true);
        txtEmail.setEditable(true);
        txtFirstName.setEditable(true);
        txtLastName.setEditable(true);
        txtPhone.setEditable(true);
        txtSpeciality.setEditable(true);
        txaAddress.setEditable(true);
        txaAward.setEditable(true);
        cmbAvailability.setEnabled(true);
        cmbFactualy.setEnabled(true);
        flag=1;
    }//GEN-LAST:event_btnEditDoctorActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
    // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void listDoctorValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listDoctorValueChanged
        // TODO add your handling code here:        
        int i = listDoctor.getSelectedIndex();
        if(i==-1){
            index=-1;
            return;
        }
        btnSaveChange.setEnabled(false);
        txtEmail.setEditable(false);
        txtFirstName.setEditable(false);
        txtLastName.setEditable(false);
        txtPhone.setEditable(false);
        txtSpeciality.setEditable(false);
        txaAddress.setEditable(false);
        txaAward.setEditable(false);
        cmbAvailability.setEnabled(false);
        cmbFactualy.setEnabled(false);
        
        Doctor dt =(Doctor) v.get(i);
        index = dt.getDoctorID();
        txtFirstName.setText(dt.getFirstName());
        txtLastName.setText(dt.getLastName());
        txtEmail.setText(dt.getEmail());
        txtPhone.setText(dt.getPhone());
        txtSpeciality.setText(dt.getSpeciality());
        txaAddress.setText(dt.getAddress());
        txaAward.setText(dt.getAward());
        cmbAvailability.setSelectedIndex(dt.getAvailability());
        for (int j=0;j<fac.size();j++){
            Factualy f = new Factualy();
            f=(Factualy) fac.get(j);
            if (f.getFactualyID()==dt.getFactualyID()){
                cmbFactualy.setSelectedIndex(j);
            }
        }
    }//GEN-LAST:event_listDoctorValueChanged
    private void create_list(){
        v=null;              
        String select = cmbFillter.getSelectedItem().toString();                        
        try{
        if (txtLookFor.getText().length()==0){
            v=Doctor.getAllDoctor();
        }
        }catch(SQLException sqle){
            sqle.printStackTrace();
        }
        if (txtLookFor.getText().length()!=0){
        try{
         if (select=="ID"){         
             try{
             v=Doctor.getDoctorByID(Integer.parseInt(txtLookFor.getText()));
             }catch(Exception e){
                JOptionPane.showMessageDialog(this,"ID error");
             }
         }        
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
         if (select=="Name"){             
             v=Doctor.getDoctorByName(txtLookFor.getText());
         }        
        }catch(Exception e){
            e.printStackTrace();                       
        }        
        }
        DefaultListModel model = new DefaultListModel();
        if (v!=null){
            for(int i=0;i<v.size();i++){
                if(select=="Name"){
                    Doctor dt = (Doctor) v.get(i);
                    model.addElement(dt.getFirstName()+ "  " +dt.getLastName());                    
                }
                else{
                    Doctor dt = (Doctor) v.get(i);
                    model.addElement(dt.getDoctorID());                
                }
        }
        }
        listDoctor.setModel(model);           
    
    }
    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        // TODO add your handling code here:
        create_list();
    }//GEN-LAST:event_btnSearchActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEditDoctor;
    private javax.swing.JButton btnInsert;
    private javax.swing.JButton btnSaveChange;
    private javax.swing.JButton btnSearch;
    private javax.swing.JComboBox cmbAvailability;
    private javax.swing.JComboBox cmbFactualy;
    private javax.swing.JComboBox cmbFillter;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblAvailabitily;
    private javax.swing.JLabel lblAward;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFactualy;
    private javax.swing.JLabel lblFiltered;
    private javax.swing.JLabel lblFirstName;
    private javax.swing.JLabel lblHead;
    private javax.swing.JLabel lblLastName;
    private javax.swing.JLabel lblLookFor;
    private javax.swing.JLabel lblPhone;
    private javax.swing.JLabel lblSpeciality;
    private javax.swing.JList listDoctor;
    private javax.swing.JPanel pnlHead;
    private javax.swing.JPanel pnlInformations;
    private javax.swing.JPanel pnlOptions;
    private javax.swing.JTextArea txaAddress;
    private javax.swing.JTextArea txaAward;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JTextField txtLookFor;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtSpeciality;
    // End of variables declaration//GEN-END:variables
    Vector v = new Vector();    
    int index = 0;
    Vector fac = new Vector();
}
